#ifndef AT91SAM926X_H
#define AT91SAM926X_H

#include <board_id.h>
#ifdef CONF_AT91SAM9261
#include <arch/at91sam9261reg.h>
#elif defined(CONF_AT91SAM9263)
#include <arch/at91sam9263reg.h>
#endif


#define AT91SAM926X_PA_AIC           0xfffff000
	#define AIC_SMR(n)                ((n) * 4)
	#define AIC_SVR(n)		 (0x80 + ((n) * 4))
	#define AIC_IVR                       0x100
	#define AIC_FVR                       0x104
	#define AIC_ISR                       0x108
	#define AIC_IPR                       0x10c
	#define AIC_IMR                       0x110
	#define AIC_CISR                      0x114
	#define AIC_IECR                      0x120
	#define AIC_IDCR                      0x124
	#define AIC_ICCR                      0x128
	#define AIC_ISCR                      0x12c
	#define AIC_EOICR                     0x130
	#define AIC_SPU                       0x134
	#define AIC_DCR                       0x138
	#define AIC_FFER                      0x140
	#define AIC_FFDR                      0x144
	#define AIC_FFSR                      0x148

#define MAX_IRQ_NUM          (32 + 5 * 32)


#define PIOA    0
#define PIOB    1
#define PIOC    2
#ifdef CONF_AT91SAM9263
#define PIOD    3
#define PIOE    4
#endif

#define PIO_BASE(n) (AT91SAM926X_PA_PIOA + 0x200 * (n))

#define At91RstcRead(reg) \
	ReadLong(AT91SAM926X_PA_RSTC + reg)

#define At91RstcWrite(reg, val) \
	WriteLong(val, AT91SAM926X_PA_RSTC + reg)

#define At91PmcRead(reg) \
	ReadLong(AT91SAM926X_PA_PMC + reg)

#define At91PmcWrite(reg, val) \
	WriteLong(val, AT91SAM926X_PA_PMC + reg)

#define At91AicWrite(off, val) \
	WriteLong(val, AT91SAM926X_PA_AIC + off)

#define At91AicRead(off) \
	ReadLong(AT91SAM926X_PA_AIC + off)


#define INIT_STACK_BASE	 0x10000

#define SVC_STACK_BASE   (SDRAM_BASE + SDRAM_SIZE)
#define SVC_STACK_SIZE   0x00001000

#define UND_STACK_BASE   (SVC_STACK_BASE - 1 * SVC_STACK_SIZE)
#define UND_STACK_SIZE   SVC_STACK_SIZE

#define ABT_STACK_BASE   (SVC_STACK_BASE - 2 * SVC_STACK_SIZE)
#define ABT_STACK_SIZE   SVC_STACK_SIZE

#define IRQ_STACK_BASE   (SVC_STACK_BASE - 3 * SVC_STACK_SIZE)
#define IRQ_STACK_SIZE   SVC_STACK_SIZE

#define FIQ_STACK_BASE   (SVC_STACK_BASE - 4 * SVC_STACK_SIZE)
#define FIQ_STACK_SIZE   SVC_STACK_SIZE

#define GBIOS_STACK_BASE  SVC_STACK_BASE
#define GBIOS_STACK_LIMIT (FIQ_STACK_BASE - FIQ_STACK_SIZE)

// fixme: move to autoconf.h
#define GBIOS_BH_OFFSET    0

#define SDRAM_CONF_RATE_100   0x85227259

#define CONF_PERI_A           0xffff0000

// fixme

#define INITRD_BASE_ADDR   (SDRAM_BASE + SDRAM_SIZE / 4)
#define INITRD_MAX_SIZE    (SDRAM_SIZE / 4)

#define LINUX_BASE_ADDR    (INITRD_BASE_ADDR + SDRAM_SIZE / 4)
#define LINUX_MAX_SIZE     (SDRAM_SIZE / 4)

// fixme
#define ATAG_BASE          SDRAM_BASE

#define CPU_CLOCK_RATE           198656000
#define MASTER_CLOCK_VALUE		(CPU_CLOCK_RATE / 2)

#ifdef CONF_MACH_ID
#define MACH_ID       CONF_MACH_ID
#elif defined(CONF_AT91SAM9261)
#define MACH_ID       MACH_TYPE_AT91SAM9261EK
#elif defined(CONF_AT91SAM9263)
#define MACH_ID       MACH_TYPE_AT91SAM9263EK
#else
#error
#endif

#endif
